package dome4;
/*

    实现一个多态

 */

 class Shape {

    public void draw() {
        System.out.println("画图形");
    }
}

class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("画矩形");
    }
}

class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("画圆");
    }
}

class Flower extends Shape {
    @Override
    public void draw() {
        System.out.println("❀");
    }
}

public class Test1 {


    public static void drawMap() {

        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        String[] shapes = {"rect","cycle","rect","cycle","flower"};  //用循环if实现

        for (String s : shapes) {
            if(s.equals("rect")) {
                rect.draw();
            } else if(s.equals("cycle")) {
                cycle.draw();
            }else {
                flower.draw();
            }
        }
    }

    public static void main(String[] args) {

        drawMap();
    }

    public static void drawMap1() {

        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        Shape[] shapes = {rect,cycle,rect,cycle,flower}; // 用多态思想实现

        for (Shape shape : shapes) {
            shape.draw();
        }
    }

    public static void main2(String[] args) {
        drawMap1();
    }



    public static void drawMap1(Shape shape) {
        shape.draw();
    }

    public static void main1(String[] args) {

        Rect rect = new Rect();
        drawMap1(rect);

        Cycle cycle = new Cycle();
        drawMap1(cycle);

        drawMap1(new Flower());
    }
}
